package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-19 10:30
 **/
public class LeetCode5956 {

    public String firstPalindrome(String[] words) {
        int n = words.length;
        for (int i = 0; i < n; i++) {
            if (isPalindrome(words[i])) {
                return words[i];
            }
        }

        return "";
    }

    boolean isPalindrome(String str) {
        int i = 0;
        int j = str.length() - 1;
        while (i < j) {
            if (str.charAt(i) != str.charAt(j)) {
                return false;
            }

            ++i;
            --j;
        }

        return true;
    }

}
